﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace rambla.raws.rats
{
    public class scrFiles
    {
        private ratsConnection conn;

        internal scrFiles(ratsConnection conn)
        {
            this.conn = conn;
        }

        public srcFile[] items
        {
            get
            {
                return conn.getObjects<srcFile>("/src/");
            }
        }

        public void deleteItem(srcFile item)
        {
            conn.deleteObject("/src/"+ conn.Credentials.UserName + "/" + item.filename + "/");
        }

        public void createItem(string filename, string targetFilename)
        {
            conn.uploadFile("/src/", filename, targetFilename);
        }

        public srcFile getItem(string filename)
        {
            return conn.getObject<srcFile>("/src/" + conn.Credentials.UserName + "/" + filename + "/");
        }
    }

    [XmlRoot(Namespace = "http://rambla.be/raws/ns-metadata/1.0", ElementName = "params")]
    public class srcFile
    {
        ///<summary>
        ///filename of the src instance on the RATS server
        ///</summary>
        [XmlElement(IsNullable = true)]
        public string filename;

        ///<summary>
        ///last time at which the file was accessed (uploaded or used as a transcoding source)
        ///</summary>
        [XmlElement(IsNullable = true)]
        public string updated;

        ///<summary>
        ///time at which the src file will be deleted from the server
        ///</summary>
        [XmlElement(IsNullable = true)]
        public string to_be_removed;

        ///<summary>
        ///a description of the location from which the source was uploaded or imported (eg. 'upload/{username}/{filename}' in case the file was uploaded), for informational purposes only 
        ///</summary>
        [XmlElement(IsNullable = true)]
        public string original_location;
    }
}
